﻿@inject IBlogService Service
@inject IClientUriGenerator UrlGenerator 

@if (Count is not null)
{
    <span class="itemdisplay">
        <span class="mdi mdi-comment">@Count.Value</span>
    </span>
}

@code {
    [Parameter]
    public Post Data { get; set; }

    private long? Count { get; set; }

    protected override async Task OnParametersSetAsync()
    {
        try
        {
            var query = await Service.CommentService.QueryPaging(new CommentQueryRequest
            {
                Uri = UrlGenerator.Post(Data),
                Pagination = new Data.Models.Actions.Pagination
                {
                    CurrentPage = 0,
                    PageSize = 1
                }
            });
            Count = query.CurrentPage.TotalCount;
        }
        catch
        {
            Count = null;
        }
    }
}
